package com.fourfinance.model.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Future;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.fourfinance.custom.CustomSerializer;
import com.fourfinance.util.LenderConstants;

@Entity
@Table(name="LOAN")
public class Loan {
	
	@Id
	@Column(name="ID")
	@GeneratedValue
	private Long id;
	
	@NotNull
	@Column(name="REFERENCEID")
	private String referenceId;
	
	@Max(value = LenderConstants.MAX_AMOUNT, message = "Amount cannot be null")
	@Column(name="AMOUNT")
	private Long amount;
	
	@Future
	@Column(name="TERM")
	private Date term;
	
	@NotNull
	@Column(name="INTEREST")
	private Float interest;
	
	@Column(name="CREATED")
	private Date createdDate;
	
	@Column(name="EXTENDEDCOUNT")
	private Integer extendedCount;
	
	@NotNull
	@ManyToOne
	@JoinColumn(name="CLIENTID")
	@JsonBackReference
	private Client client;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getReferenceId() {
		return referenceId;
	}

	public void setReferenceId(String referenceId) {
		this.referenceId = referenceId;
	}

	@JsonSerialize(using = CustomSerializer.class)
	public Long getAmount() {
		return amount;
	}

	public void setAmount(Long amount) {
		this.amount = amount;
	}

	@JsonSerialize(using = CustomSerializer.class)
	public Date getTerm() {
		return term;
	}

	public void setTerm(Date term) {
		this.term = term;
	}

	@JsonSerialize(using = CustomSerializer.class)
	public Float getInterest() {
		return interest;
	}

	public void setInterest(Float interest) {
		this.interest = interest;
	}

	@JsonSerialize(using = CustomSerializer.class)
	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Integer getExtendedCount() {
		return extendedCount;
	}

	public void setExtendedCount(Integer extendedCount) {
		this.extendedCount = extendedCount;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}	

}
